package cn.iot.util;

import cn.iot.common.utils.SpringUtils;
import cn.iot.sys.dao.SysLeaveApplicationDao;
import cn.iot.sys.entity.SysLeaveApplication;
import lombok.Setter;
import org.activiti.bpmn.model.FlowElement;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.Expression;

/**
 * 工作流监听器
 */
public class ExecutionListener1 implements ExecutionListener {
    @Setter
    private Expression msg1;
    @Setter
    private Expression msg2;
    private SysLeaveApplicationDao sysLeaveApplicationDao = SpringUtils.getBean(SysLeaveApplicationDao.class);

    @Override
    public void notify(DelegateExecution execution) {
        System.out.println("ExecutionListener1 开始");
        FlowElement currentFlowElement = execution.getCurrentFlowElement();
        System.out.println("currentFlowElement.getName() ="+currentFlowElement.getName());
        String currentActivityId = execution.getCurrentActivityId();
        System.out.println("currentActivityId="+currentActivityId);
        String eventName = execution.getEventName();
        String processId = execution.getProcessInstanceId();
//        Object result = execution.getVariable("审核结果变量名称");
        SysLeaveApplication sysLeaveApplication = new SysLeaveApplication();
        sysLeaveApplication.setProcessId(processId);
        sysLeaveApplication.setStatus(2);
        sysLeaveApplicationDao.updStatusByProcessId(sysLeaveApplication);
    }
}
